home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
005
/
anal.bas
< prev
next >
Wrap
BASIC Source File
|
1988-11-09
|
9KB
|
352 lines
100 REM -------------------------
110 N$= "DATA ANALYSIS PROGRAMS"
120 REM -------------------------
130 OPTION BASE 1
140 DIM P(80),R(80),D(80)
150 GOSUB 6200
160 REM SET UP MENU
170 X$(1)="INPUT DATA"
180 X$(2)="PLOT DATA"
190 X$(3)="MEAN AND STANDARD DEVIATION"
200 X$(4)="3-POINT MOVING AVERAGE"
210 X$(5)="WEIGHTED MOVING AVERAGE"
220 X$(6)="4-POINT CENTERED AVERAGE"
230 X$(7)="LINEAR REGRESSION"
240 N=7 : GOSUB 7000
250 ON X GOSUB 690,920,1140,1360,1560,1760,1960
260 GOTO 150
270 REM --------------------------
280 REM DRAW AXES
290 REM --------------------------
300 CLS
310 FOR I=1 TO 21
320 LOCATE I,6 : PRINT " I"
330 NEXT I
340 FOR I=1 TO 16 STEP 5
350 LOCATE I,6 : PRINT"-"
360 LOCATE I,1
365 PRINT USING "####"; MX-(MX-MN)/4*(I-1)/5
370 NEXT I
380 LOCATE 21,8
390 FOR I= 1 TO 32
400 PRINT "-";
410 NEXT I
420 FOR I=8 TO 38 STEP 5
430 LOCATE 21,I : PRINT "I";
440 LOCATE 22,I-1 : PRINT I-7
450 NEXT I
460 RETURN
470 REM ----------------------------
480 REM SCALE DATA AND PLOT IT
490 REM ----------------------------
500 FOR I= 1 TO ND
510 P1=21-INT(20*(D(I)-MN)/(MX-MN))
520 P2=21-INT(20*(R(I)-MN)/(MX-MN))
530 IF CH$ <> "I" THEN 570
540 IF P1 > 21 OR P1 < 1 THEN GOTO 670
550 LOCATE P1,I+8 : PRINT "*"
560 GOTO 650
570 IF CH$ <> "R" THEN 610
580 IF P2 > 21 OR P2 < 1 THEN GOTO 670
590 LOCATE P2,I+8 : PRINT "+"
600 GOTO 650
610 REM MUST BE BOTH PLOTS
620 IF P1 > 21 OR P1 < 1 OR P2 > 21 OR P2 < 1 THEN 670
630 LOCATE P1,I+8 : PRINT "*"
640 LOCATE P2,I+8 : PRINT "+"
650 NEXT I
660 RETURN
670 ERF=1 : RETURN
680 RETURN
690 REM ---------------------------
700 REM "INPUT DATA"
710 REM ---------------------------
720 REM 80 DATA VALUES
730 GOSUB 6200
740 Q1$="TYPE IN DATA VALUES IN ORDER"
750 Q2$="TYPE D WHEN DONE"
760 Q3$="" : GOSUB 5000
770 ND=0
780 J=6
790 FOR I= 1 TO 80
800 LOCATE J,10
810 PRINT " "
820 LOCATE J,5
830 PRINT "VALUE ";I; TAB(20);
840 INPUT D$
850 IF D$="D" OR D$="d" THEN 910
860 ND=ND+1
870 D(I)=VAL(D$)
880 J=J+1
890 IF J=16 THEN J=6
900 NEXT I
910 RETURN
920 REM -----------------------
930 N$= "PLOT DATA ROUTINE"
940 REM -----------------------
950 Q2$="INPUT OR REDUCED OR BOTH"
955 Q3$="DATA (I OR R OR B)"
960 GOSUB 5000
970 GOSUB 5400
980 IF CH$ ="I" OR CH$ ="R" OR CH$="B" THEN 990 ELSE 970
990 Q1$="" : Q2$=""
1000 Q3$="CHOOSE MAX SCALE : "
1010 GOSUB 5000 : INPUT MX
1020 Q3$="CHOOSE MIN SCALE : "
1030 GOSUB 5000 : INPUT MN
1040 GOSUB 270
1050 ERF=0
1060 GOSUB 470
1070 IF ERF <>1 THEN 1110
1080 Q1$="DATA OUT OF RANGE"
1090 Q2$="PLEASE RESPECIFY" :BEEP
1100 GOTO 1000
1110 LOCATE 24,1
1120 PRINT "STRIKE ANY KEY TO CONTINUE";
1130 CH$=INKEY$ :IF CH$="" THEN 1130 ELSE RETURN
1140 REM ---------------------
1150 N$= "MEAN AND STANDARD DEVIATION"
1160 REM -------------------------------
1170 GOSUB 6200
1180 REM COMPUTE THE MEAN
1190 ME=0
1200 FOR I = 1 TO ND
1210 ME=ME+D(I)
1220 NEXT I
1230 ME=ME/ND
1240 REM COMPUTE STANDARD DEVIATION
1250 SD=0
1260 FOR I=1 TO ND
1270 SD=SD+(D(I)-ME)^2
1280 NEXT I
1290 SD=(SD/ND)^.5
1300 PRINT "MEAN OF INPUT DATA";TAB(20);
1310 PRINT USING "######,.##"; ME
1320 PRINT "STANDARD DEVIATION";TAB(20);
1330 PRINT USING "######,.##";SD
1340 GOSUB 7400
1350 RETURN
1360 REM ---------------------------------
1370 N$= "3-POINT MOVING AVERAGE"
1380 REM ---------------------------------
1390 GOSUB 6200
1400 REM SET UP THE RESULT IN R(I)
1410 R(1)=0 : R(2)=0 : R(3)=0
1420 FOR I = 4 TO ND
1430 R(I)=(D(I-3)+D(I-2)+D(I-1))/3
1440 NEXT I
1450 Q1$="DO YOU WANT TO PRINT THE "
1460 Q2$="DATA (Y OR N)"
1470 Q3$="" : GOSUB 5000
1480 GOSUB 7800
1490 IF YN$="N" THEN RETURN
1500 CLS
1510 FOR I = 4 TO ND
1520 PRINT R(I),
1530 NEXT I
1540 GOSUB 7400
1550 RETURN
1560 REM -----------------------------------
1570 N$= "3-PT. WEIGHTED MOVING AVERAGE"
1580 REM -----------------------------------
1590 GOSUB 6200
1600 REM SET UP THE RESULT IN R(I)
1610 R(1)=0 : R(2)=0 : R(3)=0
1620 FOR I = 4 TO ND
1630 R(I)=(D(I-3)+2*D(I-2)+3*D(I-1))/6
1640 NEXT I
1650 Q1$="DO YOU WANT TO PRINT THE"
1660 Q2$="DATA (Y OR N)"
1670 Q3$="" : GOSUB 5000
1680 GOSUB 7800
1690 IF YN$="N" THEN RETURN
1700 CLS
1710 FOR I = 4 TO ND
1720 PRINT R(I),
1730 NEXT I
1740 GOSUB 7400
1750 RETURN
1760 REM -------------------------------
1770 N$= "4-PT. CENTERED AVERAGE"
1780 REM -------------------------------
1790 GOSUB 6200
1800 REM SET UP THE RESULT IN R(I)
1810 R(1)=0 : R(2)=0 : R(3)=0 : R(4)=0 : R(5)=0
1820 FOR I = 6 TO ND
1830 R(I)=(D(I-5)+2*(D(I-4)+D(I-3)+D(I-2))+D(I-1))/8
1840 NEXT I
1850 Q1$="DO YOU WANT TO PRINT THE "
1860 Q2$="DATA (Y OR N)"
1870 Q3$="" : GOSUB 5000
1880 GOSUB 7800
1890 IF YN$="N" THEN RETURN
1900 CLS
1910 FOR I = 4 TO ND
1920 PRINT R(I),
1930 NEXT I
1940 GOSUB 7400
1950 RETURN
1960 REM -----------------------------
1970 N$= "LINEAR REGRESSION"
1980 REM -----------------------------
1990 GOSUB 6200
2000 SX=0 : SY=0 : SXY=0 : SX2=0
2010 FOR I = 1 TO ND
2020 SX=SX+I
2030 SY=SY+D(I)
2040 SXY=SXY+D(I)*I
2050 SX2=SX2+I^2
2060 NEXT I
2070 M=(SXY-SX*SY/ND)/(SX2-SX^2/ND)
2080 B=SY/ND-M*SX/ND
2090 PRINT " Y=";M;"X + " ;B
2100 REM UPDATE RESULT ARRAY
2110 FOR I= 1 TO ND
2120 R(I)=B+M*I
2130 NEXT I
2140 GOSUB 7400
2150 RETURN
3000 REM
3020 OPEN F$ FOR APPEND AS #1
3030 K=1 : GOSUB 6200
3040 Q1$="ENTER DATA"
3050 Q2$=""
3060 FOR L= 1 TO NF
3070 Q3$=F$(L) : GOSUB 5800
3080 NEXT L
3090 WRITE#1,P$(1),P$(2),P$(3),P$(4),P$(5),P$(6),P$(7),P$(8)
3100 REM SEE IF MORE RECORDS TO BE ADDED
3110 Q1$="ADD ANOTHER RECORD ? "
3120 Q2$="" :Q3$="YES OR NO"
3130 GOSUB 5000
3140 GOSUB 7800
3150 IF YN$="Y" GOTO 3030
3160 CLOSE : RETURN
3400 REM "ANOTH"
3420 Q1$="WOULD YOU LIKE TO "
3430 Q3$="AGAIN Y OR N ?"
3440 GOSUB 5000
3450 GOSUB 7800
3460 RETURN
3800 REM "BACKFIL"
3820 OPEN F$ FOR INPUT AS #1
3830 OPEN FB$ FOR OUTPUT AS #2
3840 'READ A RECORD, THEN WRITE IT
3850 FOR I= 1 TO 4000
3860 IF EOF(1) THEN5$,P6$,P7$,P8$
4740 NEXT I
4750 REM READ BUT DONT WRITE RECORD TO DELETE
4760 INPUT#1,P1$,P2$,P3$,P4$,P5$,P6$,P7$,P8$
4770 REM READ AND WRITE TILL END OF FILE
4780 FOR I= 1 TO 4000
4790 IF EOF(1) THEN GOTO 4840
4800 INPUT#1,P1$,P2$,P3$,P4$,P5$,P6$,P7$,P8$
4810 WRITE#2,P1$,P2$,P3$,P4$,P5$,P6$,P7$,P8$
4820 NEXT I
4830 REM NORMAL RETURN
4840 CLOSE : RETURN
4850 REM ERROR RETURN
4860 CLOSE
4870 L=-1
4880 RETURN
5000 REM "DIALOG"
5020 FOR I= 20 TO 23
5030 LOCATE I,1
5040 IF I>20 5$,P6$,P7$,P8$
4740 NEXT I
4750 REM READ BUT DONT WRITE RECORD TO DELETE
4760 INPUT#1,P1$,P2$,P3$,P4$,P5$,P6$,P7$,P8$
4770 REM READ AND WRITE TILL END OF FILE
4780 FOR I= 1 TO 4000
4790 IF EOF(1) THEN GOTO 4840
4800 INPUT#1,P1$,P2$,P3$,P4$,P5$,P6$,P7$,P8$
4810 WRITE#2,P1$,P2$,P3$,P4$,P5$,P6$,P7$,P8$
4820 NEXT I
4830 REM NORMAL RETURN
4840 CLOSE : RETURN
4850 REM ERROR RETURN
4860 CLOSE
4870 L=-1
4880 RETURN
5000 REM "DIALOG"
5020 FOR I= 20 TO 23
5030 LOCATE I,1
5040 IF I>20 THEN 5080
5050 FOR J= 1 TO 40
5060 PRINT "-";
5070 NEXT J
5080 IF I = 21 THEN PRINT Q1$; 'FIRST QUESTION
5090 IF I = 22 THEN PRINT Q2$
5100 IF I = 23 THEN PRINT Q3$;
5110 CP1=POS(N)
5120 CP=POS(N)
5130 IF CP>40 THEN 5150
5140 PRINT " "; : GOTO 5120
5149 REM RESTORE CURSOR FOR USER RESPONSE
5150 LOCATE I,CP1
5160 NEXT I
5170 RETURN
5400 REM "INCH"
5420 REM WAIT FOR INPUT CHARACTER
5430 CH$= INKEY$ : IF CH$="" THEN 5430
5440 Z=ASC(CH$)
5450 IF Z < 97 OR Z > 122 THEN 5470
5460 Z=Z-32
5470 CH$=CHR$(Z)
5480 RETURN
5800 REM "INDAT"
5820 GOSUB 5000
5830 INPUT P$(K)
5840 REM ECHO QUESTION AND ANSWER
5850 LOCATE K+2,3
5860 PRINT Q3$;TAB(25);P$(K)
5870 K=K+1
5880 RETURN
6200 REM "INIT"
6220 CLS
6230 PRINT N$ : PRINT
6240 KEY OFF
6250 RETURN
6600 REM "INPAR"
6620 GOSUB 5000
6630 INPUT PAR(K)
6640 REM ECHO QUESTION AND ANSWER
6650 LOCATE K+2,3
6660 PRINT Q3$; TAB(24);
6670 PRINT USING "######,.##"; PAR(K)
6680 K=K+1
6690 RETURN
7000 REM "MENU"
7020 CLS
7030 FOR I= 1 TO N
7040 IF I=10 THEN PRINT 0; ELSE PRINT I;
7050 PRINT "= " ; X$(I)
7060 NEXT I
7070 Q1$="" : Q2$=""
7080 Q3$="CHOOSE PROGRAM :"
7090 GOSUB 5000
7100 GOSUB 5400
7110 X= VAL(CH$)
7119 REM SEE IF CHAR IN RANGE
7120 IF X>=1 AND X<=N THEN RETURN
7130 IF X=0 AND N=10 THEN 7140 ELSE 7150
7140 X=10 : RETURN
7150 Q1$="ILLEGAL CHOICE, CHOOSE AGAIN"
7160 GOSUB 5000
7170 GOTO 7100
7400 REM "PAUSE"
7420 Q1$="STRIKE ANY KEY TO CONTINUE"
7430 Q2$="" : Q3$=""
7440 GOSUB 5000
7450 X$=INKEY$ : IF X$ = "" THEN 7450
7460 RETURN
7800 REM "YESNO"
7820 REM WAIT FOR KEY TO BE STRUCK
7830 YN$=INKEY$ : IF YN$="" THEN 7830
7840 IF YN$="y" THEN YN$="Y"
7850 IF YN$="n" THEN YN$="N"
7860 IF YN$ = "Y" OR YN$ = "N" THEN 7890
7870 REM NOT YES OR NO TRY AGAIN
7880 GOTO 7830
7890 PRINT YN$ : RETURN